#pragma once
#ifndef __TEXTURE2D_H__
#define __TEXTURE2D_H__

#include "Utility.h"

#include "../util/D3DCommon.h"
#include "../util/PreDeclare.h"

namespace WindGE
{
	class WIND_CORE_API Texture2D
	{
	public:
		Texture2D();
		~Texture2D();

		void init_desc(const D3D11_TEXTURE2D_DESC& texDesc);
		
		void init_desc(unsigned int width, unsigned int height, DXGI_FORMAT format,
					   unsigned int miplevel = 0, unsigned int arraySize = 1,
					   unsigned int sampleCount = 1, unsigned int sampleQuality = 0,
				       D3D11_USAGE usage = D3D11_USAGE_DEFAULT,
					   unsigned int bindFlag = D3D11_BIND_SHADER_RESOURCE,
					   unsigned int cpuaccessFlag = 0,
					   unsigned int miscFlags = 0);

		void init_desc(unsigned int bindFlags, D3D11_USAGE usage, unsigned int cpuAccess,
					   DXGI_FORMAT format = DXGI_FORMAT_FROM_FILE,
					   unsigned int filter = D3DX11_FILTER_NONE,
					   unsigned int mipFilter = D3DX11_FILTER_LINEAR);

		bool init_buffer(void* buffer, unsigned int sysMemPitch, unsigned int sysMemSlicePitch);
		bool init_buffer(const void* bufferData, unsigned long bufferSize);

		bool init_tex();
		bool init_tex(const std::string& path);

		bool create(ID3D11Texture2D* tex);
		bool create(RenderDevicePtr renderDevice);

		void release();

		bool map(void** data, unsigned int mapType);
		bool map(D3D11_MAPPED_SUBRESOURCE* pResource, unsigned int subResource, D3D11_MAP maptype, unsigned int mapflags);

		void unmap(unsigned int subResource = 0);

		inline const D3D11_TEXTURE2D_DESC& desc()  { tex_->GetDesc(&tex_desc_); return tex_desc_; }
		inline ID3D11Texture2D* d3dptr() const { return tex_; }

	private:
		void*					buffer_data_;
		unsigned long			buffer_size_;

		ID3D11Texture2D*		tex_;
		D3D11_TEXTURE2D_DESC	tex_desc_;
		D3DX11_IMAGE_LOAD_INFO  image_info_;
	};

}//end namespace WindGE

#endif	//__TEXTURE2D_H__
